package com.wwwarehouse.contract.program_operation.resources_factor_page;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.AdapterView;
import android.widget.GridView;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.tools.LogUtils;
import com.wwwarehouse.contract.adapter.SelectIndustryAdapter;
import com.wwwarehouse.contract.adapter.SupplyOfResourcesAdapter;
import com.wwwarehouse.contract.bean.ChooseModuleBean;
import com.wwwarehouse.contract.bean.SupplyOfResourcesBean;
import com.wwwarehouse.contract.core.ContractConstant;
import com.wwwarehouse.contract.event.HaveResourceEvent;
import com.wwwarehouse.contract.event.IndusEvent;
import com.wwwarehouse.contract.event.NeedResourceEvent;
import com.wwwarehouse.contract.event.ResourceEvent;

import java.util.ArrayList;
import java.util.List;

import contract.wwwarehouse.com.contract.R;
import de.greenrobot.event.EventBus;

/**
 * Created by feng.gao on 2017/9/23.
 * 拥有的资源要素具体页
 */

public class HaveResourceFactorFragment extends BaseFragment {
	private GridView mGridView;
	private SupplyOfResourcesAdapter mSupplyOfResourcesAdapter;
	List<ChooseModuleBean.ModuleList.BeanList> beanLists = new ArrayList<>();
	private boolean isFunction;

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		return inflater.inflate(R.layout.supply_of_resources_fragment, container, false);
	}

	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		mGridView = (GridView) view.findViewById(R.id.grid_view);
		isFunction = getArguments().getBoolean(ContractConstant.KEY_IS_FUNCTION);

	}

	@Override
	public void setTitle() {

	}

	@Override
	public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
		if (enter) {
			if (getArguments() != null && getArguments().getSerializable(ContractConstant.KEY_BUNDLE_VIEW_PAGER_DATA) != null) {
				final ChooseModuleBean moduleBean = (ChooseModuleBean) getArguments().getSerializable(ContractConstant.KEY_BUNDLE_VIEW_PAGER_DATA);
				int position = getArguments().getInt(ContractConstant.KEY_BUNDLE_POSITION);
				int pageNum = getArguments().getInt(ContractConstant.KEY_BUNDLE_PAGENUM);
				beanLists.clear();
				for (int i = position * pageNum; i < (position + 1) * pageNum; i++) {
					if (i >= 0 && i < moduleBean.getModuleList().getList().size()) {
						beanLists.add(moduleBean.getModuleList().getList().get(i));
					}
				}
				mSupplyOfResourcesAdapter = new SupplyOfResourcesAdapter(beanLists, mActivity , isFunction);
				mGridView.setAdapter(mSupplyOfResourcesAdapter);
				mSupplyOfResourcesAdapter.setOncheckListener(new SupplyOfResourcesAdapter.checkedListener() {
					@Override
					public void onCheckedListener(ChooseModuleBean.ModuleList.BeanList lists) {
						EventBus.getDefault().post(new HaveResourceEvent(lists));

					}
				});
//				mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//					@Override
//					public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//						ChooseModuleBean.ModuleList.BeanList list = beanLists.get(position);
//						if (list.getSelected() == 1 && isFunction) {
//							return;
//						}
//						if (list.isSelect()) {
//							list.setSelect(false);
//						} else {
//							list.setSelect(true);
//						}
//						mSupplyOfResourcesAdapter.notifyDataSetChanged();
//						EventBus.getDefault().post(new HaveResourceEvent(list));
//					}
//				});

			}
		}
		return null;
	}

	@Override
	public void requestDatas() {


	}

}